package stream;

import pojo.Student;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class GroupByStream2 {
    public static void main(String[] args) {
        Stream<Student> stream = Stream.of(
                new Student("101", "猪八戒", 80),
                new Student("102", "小白龙", 80),
                new Student("103", "猪八戒", 80),
                new Student("104", "小白龙", 100),
                new Student("105", "猪八戒", 100)
        );
        /**
         * Map<String,Map<String,student>>
         *     map里面嵌套map
         *     外层 key---Integer
         *     Value-----Map
         */
        Map<Integer, Map<String, List<Student>>> map = stream.collect(Collectors.groupingBy(s -> s.getAge(),
                Collectors.groupingBy(s -> {
                    if (s.getName().equals("猪八戒")) {
                        return "猪";
                    } else
                        return "龙";
                })));
        map.forEach((k, v) -> {
            System.out.println("k = " + k);
            v.forEach((k2,v2)-> System.out.println(k2+"--"+v2));
        });
    }
}
